<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鼠标跟随生成艺术 - 原始版本</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/p5.min.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #000;
            font-family: Arial, sans-serif;
            overflow: hidden;
        }
        .controls {
            position: absolute;
            top: 10px;
            left: 10px;
            color: white;
            background: rgba(0, 0, 0, 0.7);
            padding: 10px;
            border-radius: 5px;
            font-size: 12px;
            line-height: 1.4;
            z-index: 1000;
        }
    </style>
</head>
<body>
    <div class="controls">
        <div>移动鼠标控制图案中心</div>
        <div>保持原始算法结构</div>
    </div>

    <script>
        // 原始代码的忠实转换
        let t = 0;
        let w = 400;
        let mouseX = 200;
        let mouseY = 200;
        
        function setup() {
            createCanvas(windowWidth, windowHeight);
            background(9);
            stroke(255, 96);
        }
        
        function draw() {
            // 保持原始的背景和描边设置
            background(9);
            stroke(255, 96);
            
            // 更新时间
            t += PI / 120;
            
            // 原始循环，但使用鼠标位置
            for (let i = 1e4; i > 0; i--) {
                a(i / 345);
            }
        }
        
        // 原始函数，添加鼠标跟随
        function a(y) {
            // 计算k值 - 保持原始逻辑
            let k = (y < 11 ? 6 + sin(pow(y, 8)) * 6 : y / 5 + cos(y / 2)) * cos(t - t / 4);
            
            // 计算e值
            let e = y / 7 - 13;
            
            // 计算d值 - 使用原始的mag函数逻辑
            let d = mag(k, e) + sin(e / 4 + t) / 2;
            
            // 计算c值
            let c = d / 2 + 1 - t / 2;
            
            // 计算q值
            let q = y * k / d * (3 + sin(d * 2 + y / 2 - t * 4));
            
            // 计算点位置 - 将固定的200, -170替换为鼠标位置
            let x = q + 60 * cos(c) + mouseX;
            let yPos = q * sin(c) + d * 29 - 170 + mouseY;
            
            // 绘制点
            point(x, yPos);
        }
        
        // 鼠标移动事件
        function mouseMoved() {
            mouseX = pmouseX;
            mouseY = pmouseY;
        }
        
        // 鼠标拖拽事件
        function mouseDragged() {
            mouseX = pmouseX;
            mouseY = pmouseY;
        }
        
        // 窗口大小调整
        function windowResized() {
            resizeCanvas(windowWidth, windowHeight);
            background(9);
        }
    </script>
</body>
</html>